<?php
if (!class_exists('AlfaTBSTemplateEngine')) {
	require_once("lib/tbs.php");

	/**
	 * @author Alecsandru Gabriel DINU
	 * @since Jun 11, 2008
	 */	
	class AlfaTBSTemplateEngine  {
		const TEMPLATES_PATH = "src/main/www/pages/templates";
		const PAGES_PATH = "src/main/www/pages/content";
		private $TBS;
		private $pagesLocation;
		private $templatesLocation;
		private $templateName;
		private $pageName;

		public function __construct($templateName, $pageName){
			$config = AlfaConfiguration::getInstance();
			$this->pagesLocation = $config->getString("webapp/decorator/pagesLocation", self::PAGES_PATH);		
			$this->templatesLocation = $config->getString("webapp/decorator/templatesLocation", self::TEMPLATES_PATH);
		
			$this->templateName = $templateName;
			$this->pageName = $pageName;
			$this->TBS = new clsTinyButStrong ;

			global $_RESULT_PAGE;
			global $messages;

			$_RESULT_PAGE = $this->pagesLocation . "/" . $pageName;
			$this->TBS->LoadTemplate($this->templatesLocation . "/" . $templateName);
		}

		public function mergeBlock($name, $block) {
			$this->TBS->MergeBlock($name,$block);
		}
		
		public function addObject($objectName, $objectRef) {
			$this->TBS->ObjectRef[$objectName] = &$objectRef;
		}

		public function mergeGlobal($NameLst,$Value=null) {
			eval ("global \$$NameLst;\$$NameLst = \$Value;");
		}
		
		function mergeField($NameLst,$Value=null,$IsUserFct=false) {
			$this->TBS->MergeField($NameLst,$Value,$IsUserFct);
		}
		
		public function show() {
			$this->TBS->Show() ;
		}

	}
}